﻿<primitives:BorderlessWindow x:Class="Neurotoxin.Godspeed.Shell.Views.FreestyleDatabaseCheckerWindow" 
                             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                             xmlns:primitives="clr-namespace:Neurotoxin.Godspeed.Shell.Primitives" 
                             xmlns:lex="http://wpflocalizeextension.codeplex.com"
                             xmlns:converters="clr-namespace:Neurotoxin.Godspeed.Shell.Converters"
                             lex:ResxLocalizationProvider.DefaultAssembly="Neurotoxin.Godspeed.Shell"
                             lex:ResxLocalizationProvider.DefaultDictionary="Resources"
                             MinWidth="320" MinHeight="240" Width="640" Height="480" 
                             Title="{lex:LocText ErrorsInFreestyleDatabase}">
    <primitives:BorderlessWindow.Resources>
        <converters:ExpanderConverter x:Key="ExpanderConverter"/>

        <ControlTemplate TargetType="DataGridRow" x:Key="DataGridRowTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <ToggleButton x:Name="Expander" Width="11" Height="11" Padding="0,-4,0,0" ClickMode="Press" Visibility="Collapsed"
                              Content="{TemplateBinding DetailsVisibility, Converter={StaticResource ExpanderConverter}}" 
                              IsChecked="{Binding Path=DetailsVisibility, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, Converter={StaticResource BoolToVis}}"/>

                <DataGridCellsPresenter Grid.Column="1" Grid.Row="0" />
                <DataGridDetailsPresenter Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" 
                                          SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen, ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical}, Converter={x:Static DataGrid.RowDetailsScrollingConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" 
                                          Visibility="{TemplateBinding DetailsVisibility}" />
                <Rectangle Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" StrokeThickness="1" Stroke="Black" StrokeDashArray="1 2" SnapsToDevicePixels="true" Opacity="0" x:Name="Focus" />
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter TargetName="Focus" Property="Opacity" Value="1" />
                </Trigger>
                <Trigger Property="Tag" Value="Details">
                    <Setter TargetName="Expander" Property="Visibility" Value="Visible"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

        <Style TargetType="DataGridCell" x:Key="GridCell">
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background" Value="Transparent" />
                    <Setter Property="Foreground" Value="Black" />
                </Trigger>
            </Style.Triggers>
            <Setter Property="FocusVisualStyle">
                <Setter.Value>
                    <Style>
                        <Setter Property="Control.Template">
                            <Setter.Value>
                                <ControlTemplate />
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="DataGridCell">
                        <Grid Name="Root" Background="{TemplateBinding Background}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <ContentPresenter Content="{TemplateBinding Content}" 
                                                      ContentTemplate="{TemplateBinding ContentTemplate}"
                                                      HorizontalAlignment="{TemplateBinding HorizontalAlignment}" 
                                                      VerticalAlignment="{TemplateBinding VerticalAlignment}"
                                                      Margin="{TemplateBinding Padding}" />
                            <Rectangle Name="RightGridLine" Grid.Column="1" VerticalAlignment="Stretch" Width="1" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="DataGrid" x:Key="Grid">
            <Setter Property="AutoGenerateColumns" Value="False"/> 
            <Setter Property="IsTextSearchEnabled" Value="False"/> 
            <Setter Property="Background" Value="White"/> 
            <Setter Property="SelectionMode" Value="Single"/> 
            <Setter Property="GridLinesVisibility" Value="None"/>
            <Setter Property="CanUserAddRows" Value="False"/> 
            <Setter Property="CanUserReorderColumns" Value="False"/>
            <Setter Property="CanUserDeleteRows" Value="False"/> 
            <Setter Property="CanUserResizeRows" Value="False"/>
            <Setter Property="CanUserResizeColumns" Value="True"/> 
            <Setter Property="CanUserSortColumns" Value="False"/> 
            <Setter Property="SelectionUnit" Value="FullRow"/> 
            <Setter Property="RowHeaderWidth" Value="0"/>
            <Setter Property="Focusable" Value="False"/>
            <Setter Property="ClipboardCopyMode" Value="None"/> 
            <Setter Property="BorderBrush" Value="{StaticResource NormalBorderBrush}"/>
            <Setter Property="CellStyle" Value="{StaticResource GridCell}"/>
        </Style>
        <DataTemplate x:Key="NameColumnTemplate">
            <Grid Background="Transparent">
                <StackPanel Orientation="Horizontal">
                    <Image Source="{Binding Thumbnail}" Width="16" Height="16" Margin="2,0,3,0" />
                    <TextBlock FontWeight="Bold" Text="{Binding Title}"/>
                </StackPanel>
            </Grid>
        </DataTemplate>
    </primitives:BorderlessWindow.Resources>
    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
            
        <TabControl>
            <TabItem Visibility="{Binding HasMissingFolders, Converter={StaticResource BoolToVis}}" Header="{Binding MissingFoldersCount}">
                <TabItem.HeaderTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{lex:Loc MissingGames}"/>
                            <Border CornerRadius="8" Background="#dc0d17" Margin="3,1,0,0">
                                <TextBlock Text="{Binding}" Foreground="White" FontWeight="Bold" Margin="5,0,5,0" FontSize="10" />
                            </Border>
                        </StackPanel>
                    </DataTemplate>
                </TabItem.HeaderTemplate>
                    
                <TabItem.Content>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" Text="{lex:Loc TheFollowingGamesAreMissing}" HorizontalAlignment="Left" Margin="0,0,0,10" TextWrapping="Wrap" />

                        <DataGrid Grid.Row="1" ItemsSource="{Binding MissingFolders}" Style="{StaticResource Grid}">
                            <DataGrid.RowStyle>
                                <Style TargetType="DataGridRow">
                                    <Setter Property="Template" Value="{StaticResource DataGridRowTemplate}"/>
                                </Style>
                            </DataGrid.RowStyle>
                            <DataGrid.Columns>
                                <DataGridTemplateColumn Header="{lex:LocText Neurotoxin.Godspeed.Shell:Resources:Name}" Width="Auto" IsReadOnly="True" CellTemplate="{StaticResource NameColumnTemplate}"/>
                                <DataGridTextColumn Header="{lex:LocText Neurotoxin.Godspeed.Shell:Resources:Path}" Width="*" IsReadOnly="True" Binding="{Binding Path}"/>
                            </DataGrid.Columns>
                        </DataGrid>
                    </Grid>
                </TabItem.Content>
            </TabItem>
            <TabItem Visibility="{Binding HasMissingEntries, Converter={StaticResource BoolToVis}}" Header="{Binding MissingEntriesCount}">
                <TabItem.HeaderTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{lex:Loc PossibleLeftovers}"/>
                            <Border CornerRadius="8" Background="#dc0d17" Margin="3,1,0,0">
                                <TextBlock Text="{Binding}" Foreground="White" FontWeight="Bold" Margin="5,0,5,0" FontSize="10" />
                            </Border>
                        </StackPanel>
                    </DataTemplate>
                </TabItem.HeaderTemplate>

                <TabItem.Content>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Column="0" Grid.Row="0" Text="{lex:Loc TheFollowingGamesMightHaveLeftovers}" HorizontalAlignment="Left" Margin="0,10,0,10" TextWrapping="Wrap" />

                        <DataGrid Grid.Column="0" Grid.Row="1" ItemsSource="{Binding MissingEntries}" Style="{StaticResource Grid}">
                            <DataGrid.RowStyle>
                                <Style TargetType="DataGridRow">
                                    <Setter Property="Tag" Value="Details"/>
                                    <Setter Property="Template" Value="{StaticResource DataGridRowTemplate}"/>
                                </Style>
                            </DataGrid.RowStyle>
                            <DataGrid.Columns>
                                <DataGridTemplateColumn Header="{lex:LocText Neurotoxin.Godspeed.Shell:Resources:Name}" Width="Auto" IsReadOnly="True" CellTemplate="{StaticResource NameColumnTemplate}"/>
                                <DataGridTextColumn Header="{lex:LocText Neurotoxin.Godspeed.Shell:Resources:Path}" Width="*" IsReadOnly="True" Binding="{Binding Path}"/>
                                <DataGridTextColumn Header="{lex:LocText Neurotoxin.Godspeed.Shell:Resources:Size}" Width="80" IsReadOnly="True" Binding="{Binding Size, Converter={StaticResource SizeConverter}}">
                                    <DataGridTextColumn.ElementStyle>
                                        <Style TargetType="TextBlock">
                                            <Setter Property="HorizontalAlignment" Value="Right" />
                                        </Style>
                                    </DataGridTextColumn.ElementStyle>
                                </DataGridTextColumn>
                            </DataGrid.Columns>
                            <DataGrid.RowDetailsTemplate>
                                <DataTemplate>
                                    <ItemsControl ItemsSource="{Binding Content}">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <Border Padding="32,2,0,2">
                                                    <!-- Background="{Binding ContentType, Converter={StaticResource ContentTypeConverter}}" -->
                                                    <DockPanel>
                                                        <TextBlock DockPanel.Dock="Right" Text="{Binding Size, Converter={StaticResource SizeConverter}}"/>
                                                        <TextBlock Text="{Binding Title}"/>
                                                    </DockPanel>
                                                </Border>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </DataTemplate>
                            </DataGrid.RowDetailsTemplate>
                        </DataGrid>

                        <StackPanel Grid.Column="0" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,5,0,0">
                            <Button MinWidth="75" Content="{lex:Loc Cleanup}" Margin="5,0,0,0" Command="{Binding CleanUpCommand}"/>
                        </StackPanel>
                    </Grid>
                </TabItem.Content>
            </TabItem>
        </TabControl>

        <StackPanel Grid.Row="5" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10,0,0">
            <Button Width="75" Content="{lex:LocText Ok}" Margin="5" Command="{Binding CloseCommand}" />
        </StackPanel>
    </Grid>
</primitives:BorderlessWindow>